home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Misc / msql-1.0.6 / src / conf / mmap.c < prev    next >
C/C++ Source or Header  |  1994-10-16  |  662b  |  43 lines

  1. /*
  2. ** A small test program to see if we can do shared read/write mapped
  3. ** regions.
  4. **
  5. **                        bambi
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <sys/types.h>
  10. #include <fcntl.h>
  11. #include <sys/mman.h>
  12.  
  13. #define    PATH    "/tmp/MmAp-TeSt"
  14.  
  15. main()
  16. {
  17.     int    fd,
  18.         res;
  19.     static   char    text[] = "Test Data";
  20.     caddr_t    cp;
  21.  
  22.     fd = open(PATH,O_CREAT|O_RDWR|O_TRUNC);
  23.     if (fd < 0)
  24.     {
  25.         fprintf(stderr,"mmap test : couldn't create tmp file!\n\n");
  26.         exit(1);
  27.     }
  28.     write(fd,text,strlen(text));
  29.     cp = mmap(NULL,strlen(text), PROT_READ|PROT_WRITE, MAP_SHARED, fd,0);
  30.     if (cp == (caddr_t) -1)
  31.     {
  32.         res = 1;
  33.     }
  34.     else
  35.     {
  36.         res=0;
  37.         munmap(cp,strlen(text));
  38.     }
  39.     close(fd);
  40.     unlink(PATH);
  41.     exit(res);
  42. }
  43.